//
//  UIStackViewViewController.swift
//  layoutLearn
//
//  Created by nmxy_IOS on 2020/12/28.
//

import UIKit

class UIStackViewViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        self.view.translatesAutoresizingMaskIntoConstraints = false
        self.view.layoutMargins = UIEdgeInsets  (top: 30, left: 30, bottom: 30, right: 30)
        
        let stackView = UIStackView ()
        stackView.translatesAutoresizingMaskIntoConstraints = false
        stackView.axis = .horizontal
        stackView.distribution = .fillEqually
        stackView.spacing = 10
        stackView.isLayoutMarginsRelativeArrangement = true
        stackView.layoutMargins = UIEdgeInsets (top: 3, left: 3, bottom: 3, right: 3)
        stackView.preservesSuperviewLayoutMargins = true
        self.view.addSubview(stackView)

        NSLayoutConstraint.activate([
            stackView.leftAnchor.constraint(equalTo: self.view.leftAnchor),
            stackView.topAnchor.constraint(equalTo: self.view.topAnchor),
            stackView.rightAnchor.constraint(equalTo: self.view.rightAnchor),
            stackView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)
        ])
        
        
        print(self.view.layoutMargins)
        
        let blueView = UIView ()
        blueView.backgroundColor = UIColor.blue
        let greenView = UIView ()
        greenView.backgroundColor = UIColor.green
        
        stackView.addArrangedSubview(blueView)
        stackView.addArrangedSubview(greenView)
        
        

    }
    


}
